<?php

/**
 * This is the model class for table "{{attachment}}".
 *
 * The followings are the available columns in table '{{attachment}}':
 * @property string $id
 * @property string $path
 * @property string $uid
 * @property string $filesize
 * @property string $isactive
 * @property string $filename
 * @property integer $createtime
 * @property integer $updatetime
 */
class Attachment extends CDbActiveRecord {
	/**
	 * Returns the static model of the specified AR class.
	 * 
	 * @param string $className
	 *        	active record class name.
	 * @return Attachment the static model class
	 */
	public static function model($className = __CLASS__) {
		return parent::model ( $className );
	}
	
	/**
	 *
	 * @return string the associated database table name
	 */
	public function tableName() {
		return 'webapp.wdb_attachment';
	}
	
	/**
	 *
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array (
				array (
						'createtime, updatetime',
						'numerical',
						'integerOnly' => true 
				),
				array (
						'path',
						'length',
						'max' => 20 
				),
				array (
						'uid, filesize',
						'length',
						'max' => 10 
				),
				array (
						'isactive',
						'length',
						'max' => 1 
				),
				array (
						'filename',
						'length',
						'max' => 30 
				),
				// The following rule is used by search().
				// Please remove those attributes that should not be searched.
				array (
						'id, path, uid, filesize, isactive, filename, createtime, updatetime',
						'safe',
						'on' => 'search' 
				) 
		);
	}
	
	/**
	 *
	 * @return array relational rules.
	 */
	public function relations() {
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array ();
	}
	
	/**
	 *
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels() {
		return array (
				'id' => 'ID',
				'path' => 'Path',
				'uid' => 'Uid',
				'filesize' => 'Filesize',
				'isactive' => 'Isactive',
				'filename' => 'Filename',
				'createtime' => 'Createtime',
				'updatetime' => 'Updatetime' 
		);
	}
	
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * 
	 * @return CActiveDataProvider the data provider that can return the models
	 *         based on the search/filter conditions.
	 */
	public function search() {
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		$criteria = new CDbCriteria ();
		
		$criteria->compare ( 'id', $this->id, true );
		$criteria->compare ( 'path', $this->path, true );
		$criteria->compare ( 'uid', $this->uid, true );
		$criteria->compare ( 'filesize', $this->filesize, true );
		$criteria->compare ( 'isactive', $this->isactive, true );
		$criteria->compare ( 'filename', $this->filename, true );
		$criteria->compare ( 'createtime', $this->createtime );
		$criteria->compare ( 'updatetime', $this->updatetime );
		
		return new CActiveDataProvider ( $this, array (
				'criteria' => $criteria 
		) );
	}
	
	public function beforeSave() {
		if ($this->isNewRecord == true && $this->setSeceniro == 'create')
			$this->uid = Yii::app ()->user->id;
	}
	
	/**
	 * 
	 * 
	 */
	public function behavior() {
		return array (
				'attachment'=>array(
				'class'=>'',
				));
	}
}